﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using System.Net.Http;
using System.IO;
using System.Web.Http;
using ExpenseSystem.Core;
using ExpenseSystem.Core.Authority;
using ExpenseSystem.Core.Converter;
using ExpenseSystem.Core.CustomerModules;
using ExpenseSystem.Fether;
using ExpenseSystem.Common;
using ExpenseSystem.Lor;
using ExpenseSystem.Model;
using ExpenseSystem.Common.BaseModel;

namespace ExpenseSystem.Controllers
{
    [RoutePrefix("api/Customer")]

    public class CustomerController : ApiController
    {
        SetInhibition setInhibition;
        GetInhibition getInhibition;
        SetInhibitionMaker inhibitionMaker = new SetCustomerInhibitionMaker(new StateInhibitionMaker());
        GetInhibitionMaker getInhibitionMaker = new GetInhibitionMaker();
        public CustomerController()
        {
            setInhibition = inhibitionMaker.Make();
            getInhibition = getInhibitionMaker.Make();
        }

        CustomerFetcher fetcher = new CustomerFetcher();
        CustomerManager manager = CustomerManager.CreateInstance();

        [Route("List")]
        [HttpGet]
        public ResponseModel List([FromUri]RequestArgs paramModels)
        {
            return NormalControllerHelper.List(fetcher, "SAM_CUSTOMER_LIST", paramModels, getInhibition);
        }
        [Route("Get")]
        [HttpGet]
        public ResponseModel Get(long id)
        {
            return NormalControllerHelper.Get(fetcher, "SAM_CUSTOMER_LIST", id, getInhibition);
        }
        [Route("Export")]
        [HttpGet]
        public ResponseModel Export([FromUri]RequestArgs paramModels)
        {
            ExpFetcher<CustomerExp> fetcher = new ExpFetcher<CustomerExp>();
            return NormalControllerHelper.Export(fetcher, "SAM_CUSTOMER_LIST", RestainConverter.FromRequestArgs(paramModels));
        }
        [Route("Set")]
        [HttpPost]
        public ResponseModel Set(CustomerModel data)
        {
            return NormalControllerHelper.Set(fetcher, "SAM_CUSTOMER_SET", data, manager, setInhibition,getInhibition);
        }

        [Route("Remove")]
        [HttpPost]
        public ResponseModel Remove(CustomerModel data)
        {
            return NormalControllerHelper.Remove("SAM_CUSTOMER_DEL", data, manager);
        }

        [Route("RemoveById")]
        [HttpGet]
        public ResponseModel RemoveById([FromUri]long[] id)
        {
            return NormalControllerHelper.RemoveById("SAM_CUSTOMER_DEL", id, manager);
        }
    }
}
